package com.example.a22310.myapplication.ViewModel.Prize;


import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.example.a22310.myapplication.Adapter.MvvmAdapter;
import com.example.a22310.myapplication.Beans.Prize;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Model.PrizeModel;
import com.example.a22310.myapplication.databinding.ActivityPrizeBinding;

import java.util.List;

public class PrizeViewModel  extends Prize.PrizelistBean implements ActivityLisenter<Prize> {

    private ActivityPrizeBinding binding;
    private AppCompatActivity activity;
    private int userid;
    public PrizeViewModel(AppCompatActivity activity, ActivityPrizeBinding binding,int userid){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        binding.setDetail(this);
        PrizeModel prizeModel=new PrizeModel();
        prizeModel.prizelist(PrizeViewModel.this,userid);

    }


    public void back(View view){
        activity.onBackPressed();
    }

    @Override
    public void onSuccess(Prize prize) {
        if(prize.getCode()!=404) {
            List<Prize.PrizelistBean> prizelistBeen = prize.getPrizelist();
            binding.recyclerViewPrize.setLayoutManager(
                    new LinearLayoutManager(activity));
            MvvmAdapter adapter = new MvvmAdapter(activity, R.layout.cardview_prize,
                    prizelistBeen, BR.prize);
            binding.recyclerViewPrize.setAdapter(adapter);
        }



    }

    @Override
    public void onFailure() {
    }


}
